package tools
{
	public class SingleObject
	{
		private static var classArgs:Array = [];
		private static var singleArgs:Array = [];
		private static var index:int;
		private static var single:*;
		
		public static function getSingle(value:Class,...args):*
		{
			index = singleArgs.indexOf(value);
			if(index == -1)
			{
				single = construct(value,args);
				classArgs.push(value);
				singleArgs.push(single);
			}else
			{
				return singleArgs[index] as value;
			}
		}
		
		public static function deleteSingle(value:Class):void
		{
			index = singleArgs.indexOf(value);
			if(index != -1)
			{
				classArgs.slice(index,1);
				singleArgs.slice(index,1);
			}
		}
		
		private static function construct(value:Class,...args):*
		{
			switch(args.length)
			{
				case 0:
					return new value();
				case 1:
					return new value(args[0]);
				case 2:
					return new value(args[0],args[1]);
				case 3:
					return new value(args[0],args[1],args[2]);
				case 4:
					return new value(args[0],args[1],args[2],args[3]);
				case 5:
					return new value(args[0],args[1],args[2],args[3],args[4]);
				case 6:
					return new value(args[0],args[1],args[2],args[3],args[4],args[5] );
				case 7:
					return new value(args[0],args[1],args[2],args[3],args[4],args[5],args[6] );
				case 8:
					return new value(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7] );
				case 9:
					return new value(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8] );
				case 10:
					return new value(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9] );
				default:
					return null;
			}
		}
	}
}